<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Promise.race()</title>
</head>

<body>
    <script>
        const f1 = new Promise((resolve, reject) => {
            setTimeout(() => {
                console.log('first');
            }, 1000)
        });

        const f2 = new Promise((resolve, reject) => {
            setTimeout(() => {
                console.log('second');
            }, 500);
        });

        const f3 = Promise.reject('err');

        const f4 = Promise.resolve('fourth');

        Promise.race([f1, f2, f3, f4]).then(res => {
            console.log(res); // second first    获得reject之前得结果，用时短的结果先输出
        });
    </script>
</body>

</html>